import React, { Component } from "react";

export default class App extends Component {
    state = {
        proList: []
    }
    // 生命周期函数相当于Vue的mounted函数
    componentDidMount() {
        fetch('http://121.89.205.189/api/pro/list?limitNum=20')
            .then(res => res.json())
            .then(res => {
                console.log(res)
                this.setState({
                    proList: res.data
                })
            })
    }
    render() {
        const { proList } = this.state
        if (proList) {
            const arr = []
            proList.forEach(item => {
                arr.push(<div key={item.proid}>{item.proname}</div>)
            })
            return (
                <div>
                    <h1>数组特性</h1>
                    { arr }
                </div>
            )
        } else {
            return null
        }
    }
}